<?php

class Application_Model_VoucherGetMapper
{
	protected $_dbTable;

	public function setDbTable ($dbTable) {
		if (is_string($dbTable))
		$dbTable = new $dbTable ();
		if (!$dbTable instanceof Zend_Db_Table_Abstract)
		throw new Exception ('Invalid table data gateway provided');
		$this->_dbTable = $dbTable;
		return $this;
	}
	public function getDbTable () {
		if (null === $this->_dbTable) {
			$this->setDbTable ('Application_Model_DbTable_VoucherGet');
		}
		return $this->_dbTable;
	}
	public function insert($userinfo){//插入数据
			return $this->getDbTable()->insert($userinfo);
	}
	public function FindOpenId($openId){//从数据库查询数据只查一个字段（openId）
		$resultSet = $this->getDbTable()->fetchAll('openid = "'.$openId.'"')->toArray();
		if (count($resultSet) > 0) {
			return $resultSet[0];
		}
		return '';
	}
	public function getVoucherList(){//从数据库查询数据按update_time排序	
		$select = $this->getDbTable()->select();
		$select->from($this->getDbTable(),'*');
		$select->order('inserttime DESC');			
		$sql = $select->__toString();
		$result = $this->getDbTable()->getAdapter()->fetchAll($sql);
		return $result;
	}
	public function FindInfo($openid){//从数据库查询数据
	$where = $this->getDbTable()->getAdapter()->quoteInto('openid = ?', $openid);
	$result = $this->getDbTable()->fetchAll($where);
	return $result->toArray();
	}

}
?>


